/*
 * @lc app=leetcode.cn id=559 lang=javascript
 *
 * [559] N 叉树的最大深度
 */

// @lc code=start
/**
 * // Definition for a Node.
 * function Node(val,children) {
 *    this.val = val;
 *    this.children = children;
 * };
 */

/**
 * @param {Node|null} root
 * @return {number}
 */
var maxDepth = function (root) {
  let count = 0;
  if (root === null) {
    return count
  }
  const queque = [root]
  while (queque.length) {
    let n = queque.length
    count++
    for (let i = 0; i < n; i++){
      let node = queque.shift()
      for (let item of node.children) {
        item&&queque.push(item)
      }
    }
  }
  return count
};
// @lc code=end

